package gazzera.node.core.plugins;

import gazzera.gui.*;
import gazzera.gui.messages.*;
import gazzera.node.core.*;
import gazzera.node.core.messages.*;
import gazzera.node.core.peer.*;

public class DemoPlugin implements Plugin
{
    ICore core = null;

	@Override
	public void finish()
	{
	}

	@Override
	public void init(ICore core)
	{
	    this.core = core;
	}
	
	public void start()
	{
		
	}

	@Override
	public void taskTerminated(Task task, boolean interrupted) throws Exception
	{
	
		
	}
	
	@Override
	public void command(GuiMessage msg) throws Exception
	{
		if(msg instanceof ChatMessage)
		{
			ChatMessage x = (ChatMessage)msg;
			Node n = core.find(x.hash);
			if(n==null)
			{
				core.getGui().pass(new Log("User is not online"));
			}
			else
			{
				n.enqueue(new Chat(x.text));
			}
		}
	}

	@Override
	public void message(Node n, Message m)
	{
		if( m instanceof Chat)
		{
			Chat c = (Chat)m;
			core.getGui().pass(new ChatMessage(n.getHash(), c.text));
		}
		/*
		if (!(m instanceof ChunkData))
		{
			core.getGui().pass(new Log("MSG "+n.getHash()+" - "+m.getClass().getSimpleName()));
		}*/
	}

	@Override
	public void dataPumpTerminated(Node node, DataPumpSource src)
	{
	    
	}

	@Override
	public void nodeConnected(Node node)
	{
	}

	@Override
	public void nodeDisconnected(Node node)
	{
	    
	}
	
	

}
